package com.cdn.auth.util;

import com.cdn.auth.context.UserContext;
import com.cdn.auth.user.UserDetails;

/**
 * 蔡定努
 * 2024/06/28 17:07
 */
public class CAuthUtil {

    /**
     * @author 蔡定努
     */
    public static boolean isAdmin() {
        UserDetails userDetails = UserContext.get().getUserDetails();
        Boolean admin = userDetails.getAdmin();
        return admin != null && admin;
    }

    public static UserDetails getUserInfo() {
        return UserContext.get().getUserDetails();
    }

    /**
     * 用户ID
     **/
    public static Integer getUserId() {
        if (UserContext.get() == null) {
            return null;
        }
        return UserContext.get().getUserDetails().getUserId();
    }

    /**
     * 获取用户账户
     **/
    public static String getUsername() {
        if (UserContext.get() == null) {
            return null;
        }
        return UserContext.get().getUserDetails().getUserName();
    }

    public static Boolean checkLogin() {
        return UserContext.get() != null;
    }


}
